package com.springapi.controller;

import com.springapi.entity.Goodsclass;
import com.springapi.entity.Supplier;
import com.springapi.service.SupplierService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 供应商明细(Supplier)表控制层
 *
 * @author makejava
 * @since 2024-12-23 13:37:38
 */
@RestController
@RequestMapping("/api/supplier")
public class SupplierController {

    /**
     * 服务对象
     */
    @Resource
    private SupplierService supplierService;

    /**
     * 通过appid和shopid查询列表数据
     */
    @GetMapping("/myfindAll")
    public List<Supplier> myfindAll(@RequestParam int appid, @RequestParam int shopid) {
        return supplierService.myfindAll(appid,shopid);
    }


    /**
     * 分页查询
     *
     * @param supplier 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<Supplier>> queryByPage(Supplier supplier, PageRequest pageRequest) {
        return ResponseEntity.ok(this.supplierService.queryByPage(supplier, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<Supplier> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.supplierService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param supplier 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<Supplier> add(Supplier supplier) {
        return ResponseEntity.ok(this.supplierService.insert(supplier));
    }

    /**
     * 编辑数据
     *
     * @param supplier 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<Supplier> edit(Supplier supplier) {
        return ResponseEntity.ok(this.supplierService.update(supplier));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.supplierService.deleteById(id));
    }

}

